package com.ptszyxx.popose.module.main.dynamic.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.ItemDynamicBinding;
import com.ptszyxx.popose.module.main.dynamic.vm.DynamicTabVM;
import com.ysg.http.data.entity.dynamic.DynamicResult;

public class DynamicAdapter extends BaseQuickAdapter<DynamicResult, BaseDataBindingHolder<ItemDynamicBinding>> {

    private DynamicTabVM viewModel;
    private Presenter mPresenter = new Presenter();

    public DynamicAdapter(DynamicTabVM viewModel) {
        super(R.layout.item_dynamic);
        this.viewModel = viewModel;
    }

    @Override
    protected void convert(BaseDataBindingHolder<ItemDynamicBinding> holder, DynamicResult item) {
        ItemDynamicBinding binding = holder.getDataBinding();
        if (binding != null) {
            binding.setEntity(item);
            binding.setViewModel(viewModel);
            binding.setPresenter(mPresenter);
            binding.setPosition(holder.getBindingAdapterPosition());
            binding.executePendingBindings();

            binding.dynamicImage.setData(item);
        }
    }

    public static class Presenter{
        public void onItemClick(DynamicTabVM viewModel, DynamicResult entity){
            //动态详情
            viewModel.jumpDynamicDetail(entity);
        }
        public void onAvatarClick(DynamicTabVM viewModel, DynamicResult entity){
            viewModel.onAvatarClick(entity);
        }
        public void onLikeClick(DynamicTabVM viewModel, DynamicResult entity, int position){
            viewModel.onLikeClick(entity, position);
        }

    }








}
